<template>
	<view class="lh-w-full">
		<view v-if="filetype===0">
			<image :src="imgUrl" mode="" style="width: 100%;" ></image>
		</view>
		<view v-if="filetype===1">
			<video v-if="videoUrl!=''" class="video" :src="videoUrl" controls></video>
		</view>
		<view class="lh-w-full" v-if="filetype===2">
			<!-- <web-view v-if="pdfUrl!=''" :src="'/hybrid/html/web/viewer.html?file='+pdfUrl">
			</web-view> -->
			<!-- <web-view v-if="url!=''" :src="'http://10.1.4.19:8012/kk/onlinePreview?url='+ encodeURIComponent(url)"  > -->
			<web-view v-if="url!=''" :src="'https://ots.ez.wh.cn/kk/onlinePreview?url='+ encodeURIComponent(url)"  >
			</web-view>
			<!-- style="width:800px;transform: scale(1,1);transform-origin: left top;" -->
		</view>
	</view>
</template>
<script>
	import base64 from '@/common/base64.js';
	export default {
		data () {
			return {
				fileInfo: null,
				fileUrl: '', // 文件原始地址
				filetype: 0, // 0: 图片类 1: 视频类 2: pdf
				pdfUrl: '', // 转过后的pdf预览地址
				videoUrl: '', // 视频类预览地址
				imgUrl: '', // 图片类预览地址
				url:'',
			};
		},
		onLoad ( {filetype} ) {
			// uni.showLoading( {
			// 	title: '加载中...'
			// } );
			this.filetype = Number( filetype );
			this.fileInfo = uni.getStorageSync( 'fileInfo' );
			this.fileUrl = this.fileInfo.fileUrl;
			// if(this.filetype == 2){
			// 	this.url= base64.btoa(this.fileUrl);
			// }
			uni.removeStorageSync( 'fileInfo' );
			uni.setNavigationBarTitle( {
				title: this.fileInfo.fileName
			} );
			this.init();
		},
		onNavigationBarButtonTap ( e ) {
			this.show = true;
		},
		methods: {
			init () {

				if ( this.filetype === 0 ) {
					this.imgUrl = this.fileUrl;
				} else if ( this.filetype === 1 ) {
					this.videoUrl = this.fileUrl;
				} else if ( this.filetype === 2 ) {
					this.url= base64.btoa(this.fileUrl);
					// uni.downloadFile( {
					// 	url: this.fileUrl,
					// 	success: ( res ) => {
					// 		// debugger;
					// 		// this.pdfUrl = res.tempFilePath;
					// 		// this.pdfUrl = "blob:http://localhost:8080/922b6df1-2bef-4f8d-b7f7-2c9e415936b0"
					// 	}
					// } );
				}
				uni.hideLoading();
			},
		}
	};
</script>
<style lang="scss" scoped>
	.video {
		width: 100%;
	}
</style>
